package config

import (
	"time"

	microConfig "github.com/micro/go-micro/v2/config"
	"github.com/micro/go-micro/v2/config/source/file"
	"github.com/treelab/updatecolumn/utils"
)

//Service configuration and register
const (
	DbName    = "some_db"
	TenantKey = "tenantids"
)

//RedisCfg for redis
type RedisCfg struct {
	Url            string
	MaxIdle        int
	MaxActive      int
	Wait           bool
	MaxIdleTimeout int
}

type MongoCfg struct {
	Url string
}
type DgraphCfg struct {
	Url string
}

type Config struct {
	Host    string
	Timeout int
	Redis   RedisCfg
	Mongodb MongoCfg
	Dgrpah  DgraphCfg
}

var Cfg Config

//读取根目录下的配置，用于初始化配置
func init() {
	if err := microConfig.Load(file.NewSource(file.WithPath("default.yml"))); err != nil {
		utils.Sugar.Warnw("No config found.", "time", time.Now().String())
	} else {

		if err := microConfig.Scan(&Cfg); err != nil {
			panic(err)
		}
		utils.Sugar.Infow("config inited.", "time", time.Now().String())
	}

}
